import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// 语言切换
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n
// 全局样式
import '@/styles/index.scss' // global css
// 自定义指令
// import { imgerror, color } from '@/directives'
// 全部直接导入
import * as directives from '@/directives'
import App from './App'
import store from './store'
import router from './router'
// svg图标
import '@/icons' // icon
// 权限
import '@/permission' // permission control
import * as filters from '@/filters' // 引入过滤器
import request from './utils/request'
// import 'element-ui/lib/theme-chalk/index.css'
// 全局注册组件
import Components from './components'
// Vue.component('PageTools', PageTools)
Vue.use(Components)
import Print from 'vue-print-nb'
Vue.use(Print)
// import vueConfig from 'vue.config'
// 将request挂载到vue原型上，这样可以使用this.$requset调用
Vue.prototype.$request = request
import i18n from '@/lang'

// 配置ElementUI的中英切换逻辑
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value)
})
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// 中英文切换
// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)

Vue.config.productionTip = false

// 注册一个全局自定义指令 `v-xxx` 'v-yyy' 'v-imgerror'
// Vue.directive('imgerror', imgerror)
// Vue.directive('color', color)
// 优化1
// for (const key in directives) {
//   Vue.directive(key, directives[key])
// }
// 优化2
Object.keys(directives).forEach(item => {
  Vue.directive(item, directives[item])
})
// 优化3
// Object.keys(directives).map(item => {
//   Vue.directive(item, directives[item])
// })
// 注册全局的过滤器
Object.keys(filters).forEach(item => {
  Vue.filter(item, filters[item])
})

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
